package com.am.user.controller;
import com.am.user.domain.Result;

import com.am.user.domain.vo.PageVO;
import com.am.user.service.impl.LoginlogsServiceImpl;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author cq
 * @since 2025-02-01
 */
@RestController
@RequestMapping("/logs")
public class LoginlogsController {
    @Autowired
    LoginlogsServiceImpl loginlogsService;

    @PostMapping("/addlogs")
    Result addLogs(HttpServletRequest httpServletRequest) {
        String userAngent = httpServletRequest.getHeader("User-Agent");
        String user_id = httpServletRequest.getHeader("user-info");
        System.out.println(user_id);
        return loginlogsService.addlogs(userAngent,user_id);
    }

    @GetMapping("/pagelogs")
    Result<PageVO> logsPage(@Param("pageSize") int pageSize, @Param("pageNum") int pageNum,HttpServletRequest httpServletRequest) {
        String user_id = httpServletRequest.getHeader("user-info");
        return loginlogsService.pageLogs(pageSize, pageNum,user_id);
    }
}
